package org.htmlparser.tags;

import java.util.Locale;
import java.util.Vector;
import org.htmlparser.Attribute;
import org.htmlparser.lexer.Page;
import org.htmlparser.nodes.TagNode;
import org.htmlparser.util.ParserUtils;

public class ImageTag extends TagNode
{
  private static final String[] mIds;
  protected String imageURL = null;

  static
  {
    String[] arrayOfString = new String[1];
    arrayOfString[0] = "IMG";
    mIds = arrayOfString;
  }

  public String extractImageLocn()
  {
    Object localObject = "";
    int i = 0;
    Vector localVector = getAttributesEx();
    int j = localVector.size();
    int k = 0;
    if ((k < j) && (i < 3))
    {
      String str3;
      Attribute localAttribute = (Attribute)localVector.elementAt(k);
      String str1 = localAttribute.getName();
      String str2 = localAttribute.getValue();
      switch (i)
      {
      default:
        throw new IllegalStateException("we're not supposed to in state " + i);
      case 0:
        if (str1 != null)
        {
          str3 = str1.toUpperCase(Locale.ENGLISH);
          if (!(str3.equals("SRC")))
            break label171;
          i = 1;
          if (str2 != null)
          {
            if (!("".equals(str2)))
              break label161;
            i = 2;
          }
        }
      case 1:
      case 2:
      }
      while (true)
      {
        do
          while (true)
          {
            do
              while (true)
              {
                do
                  while (true)
                  {
                    label161: label171: 
                    do
                      while (true)
                      {
                        while (true)
                          ++k;
                        localObject = str2;
                        k = j;
                      }
                    while (!(str3.startsWith("SRC")));
                    String str4 = str1.substring(3);
                    if ((str4.startsWith("\"")) && (str4.endsWith("\"")) && (1 < str4.length()))
                      str4 = str4.substring(1, str4.length() - 1);
                    if ((str4.startsWith("'")) && (str4.endsWith("'")) && (1 < str4.length()))
                      str4 = str4.substring(1, str4.length() - 1);
                    localObject = str4;
                    i = 0;
                  }
                while ((str1 == null) || (!(str1.startsWith("="))));
                i = 2;
                if (1 >= str1.length())
                  break;
                localObject = str1.substring(1);
                i = 0;
              }
            while (str2 == null);
            localObject = str1.substring(1);
            i = 0;
          }
        while (str1 == null);
        if (str2 == null)
          localObject = str1;
        i = 0;
      }
    }
    return ((String)ParserUtils.removeChars(ParserUtils.removeChars((String)localObject, '\n'), '\r'));
  }

  public String[] getIds()
  {
    return mIds;
  }

  public String getImageURL()
  {
    if ((this.imageURL == null) && (getPage() != null))
      this.imageURL = getPage().getAbsoluteURL(extractImageLocn());
    return this.imageURL;
  }

  public void setImageURL(String paramString)
  {
    this.imageURL = paramString;
    setAttribute("SRC", this.imageURL);
  }
}